﻿using System;
using System.Collections.Generic;

using RexToy.Collections;
using RexToy.Configuration;
using RexToy.Template.AST;
using RexToy.ExpressionLanguage.AST;

namespace RexToy.UI.Web.Configuration
{
    class XmlWebConfig : ModuleConfig, IWebConfig
    {
        private const string WEB = "web";
        private const string TAG_PATH = "tagPath";
        private const string TEMPLATE_CACHE = "template-cache";
        private const string EL_CACHE = "el-cache";

        public XmlWebConfig()
        {
            this._tagPath = this.GlobalConfig.ReadValue(WEB, TAG_PATH);
            if (this.GlobalConfig.ExistsKey(WEB, TEMPLATE_CACHE))
            {
                string cache = this.GlobalConfig.ReadValue(WEB, TEMPLATE_CACHE);
                this._template_cache = Reflector.LoadInstance<ICache<string, TemplateAST>>(cache);
            }
            else
            {
                _template_cache = NoCache.GetInstance<string, TemplateAST>();
            }

            if (this.GlobalConfig.ExistsKey(WEB, EL_CACHE))
            {
                string cache = this.GlobalConfig.ReadValue(WEB, EL_CACHE);
                this._el_cache = Reflector.LoadInstance<ICache<string, ExpressionLanguageAST>>(cache);
            }
            else
            {
                _el_cache = NoCache.GetInstance<string, ExpressionLanguageAST>();
            }
        }

        private string _tagPath;
        public string TagPath
        {
            get { return _tagPath; }
        }

        private ICache<string, TemplateAST> _template_cache;
        public ICache<string, TemplateAST> TemplateASTCache
        {
            get { return _template_cache; }
        }

        private ICache<string, ExpressionLanguageAST> _el_cache;
        public ICache<string, ExpressionLanguageAST> ELCache
        {
            get { return _el_cache; }
        }
    }
}
